using System.IO;
using System.Reflection;
using GrapeCity.Documents.Excel;
using System;
using System.Data;

namespace GrapeCity.Documents.Excel.Examples.Templates.TemplateSamples.ExpenseTrendBudgetReport
{
    class Program
    {
        static void Main(string[] args)
        {
			//create a new workbook
			var workbook = new GrapeCity.Documents.Excel.Workbook();
			
			//Load template file from resource
			var templateFile = GetResourceStream("xlsx\\Template_ExpenseTrendBudgetReport.xlsx");
			workbook.Open(templateFile);
			
			#region Init Data
			var datasource = new DataTable();
			datasource.Columns.Add(new DataColumn("ExpenseName", typeof(string)));
			datasource.Columns.Add(new DataColumn("Month", typeof(string)));
			datasource.Columns.Add(new DataColumn("ExpenseData", typeof(Int32)));
			
			datasource.Rows.Add("Expense 1", "Jan", 242);
			datasource.Rows.Add("Expense 1", "Feb", 534);
			datasource.Rows.Add("Expense 1", "Mar", 24);
			datasource.Rows.Add("Expense 1", "Apr", 353);
			datasource.Rows.Add("Expense 1", "May", 456);
			datasource.Rows.Add("Expense 1", "Jun", 456);
			datasource.Rows.Add("Expense 1", "Jul", 204);
			datasource.Rows.Add("Expense 1", "Aug", 123);
			datasource.Rows.Add("Expense 1", "Sep", 530);
			datasource.Rows.Add("Expense 1", "Oct", 392);
			datasource.Rows.Add("Expense 1", "Nov", 242);
			datasource.Rows.Add("Expense 1", "Dec", 432);
			
			datasource.Rows.Add("Expense 2", "Jan", 214);
			datasource.Rows.Add("Expense 2", "Feb", 435);
			datasource.Rows.Add("Expense 2", "Mar", 345);
			datasource.Rows.Add("Expense 2", "Apr", 646);
			datasource.Rows.Add("Expense 2", "May", 757);
			datasource.Rows.Add("Expense 2", "Jun", 755);
			datasource.Rows.Add("Expense 2", "Jul", 435);
			datasource.Rows.Add("Expense 2", "Aug", 433);
			datasource.Rows.Add("Expense 2", "Sep", 240);
			datasource.Rows.Add("Expense 2", "Oct", 590);
			datasource.Rows.Add("Expense 2", "Nov", 425);
			datasource.Rows.Add("Expense 2", "Dec", 535);
			
			datasource.Rows.Add("Expense 3", "Jan", 643);
			datasource.Rows.Add("Expense 3", "Feb", 533);
			datasource.Rows.Add("Expense 3", "Mar", 644);
			datasource.Rows.Add("Expense 3", "Apr", 757);
			datasource.Rows.Add("Expense 3", "May", 856);
			datasource.Rows.Add("Expense 3", "Jun", 765);
			datasource.Rows.Add("Expense 3", "Jul", 574);
			datasource.Rows.Add("Expense 3", "Aug", 540);
			datasource.Rows.Add("Expense 3", "Sep", 530);
			datasource.Rows.Add("Expense 3", "Oct", 399);
			datasource.Rows.Add("Expense 3", "Nov", 332);
			datasource.Rows.Add("Expense 3", "Dec", 764);
			
			datasource.Rows.Add("Expense 4", "Jan", 677);
			datasource.Rows.Add("Expense 4", "Feb", 543);
			datasource.Rows.Add("Expense 4", "Mar", 607);
			datasource.Rows.Add("Expense 4", "Apr", 788);
			datasource.Rows.Add("Expense 4", "May", 332);
			datasource.Rows.Add("Expense 4", "Jun", 785);
			datasource.Rows.Add("Expense 4", "Jul", 244);
			datasource.Rows.Add("Expense 4", "Aug", 410);
			datasource.Rows.Add("Expense 4", "Sep", 600);
			datasource.Rows.Add("Expense 4", "Oct", 539);
			datasource.Rows.Add("Expense 4", "Nov", 564);
			datasource.Rows.Add("Expense 4", "Dec", 746);
			
			datasource.Rows.Add("Expense 5", "Jan", 332);
			datasource.Rows.Add("Expense 5", "Feb", 33);
			datasource.Rows.Add("Expense 5", "Mar", 809);
			datasource.Rows.Add("Expense 5", "Apr", 432);
			datasource.Rows.Add("Expense 5", "May", 675);
			datasource.Rows.Add("Expense 5", "Jun", 747);
			datasource.Rows.Add("Expense 5", "Jul", 322);
			datasource.Rows.Add("Expense 5", "Aug", 500);
			datasource.Rows.Add("Expense 5", "Sep", 300);
			datasource.Rows.Add("Expense 5", "Oct", 609);
			datasource.Rows.Add("Expense 5", "Nov", 643);
			datasource.Rows.Add("Expense 5", "Dec", 475);
			
			#endregion
			
			//Init template global settings
			workbook.Names.Add("TemplateOptions.KeepLineSize", "true");
			
			//Add data source
			workbook.AddDataSource("ds", datasource);
			//Invoke to process the template
			workbook.ProcessTemplate();
			        
			// Save to an excel file
			workbook.Save("ExpenseTrendBudgetReport.xlsx");

        }

		static Stream GetResourceStream(string resourcePath)
        {
            string resource = "ExpenseTrendBudgetReport.Resource." + resourcePath.Replace("\\", ".");
            var assembly = typeof(Program).GetTypeInfo().Assembly;
            return assembly.GetManifestResourceStream(resource);
        }

    }
}